package com.lhframework.sms.api;

import com.lhframework.sms.constant.SmsTemplateCode;
import com.lhframework.sms.constant.SmsTemplateName;
import com.lhframework.sms.model.ShortMessage;
import com.lhframework.sms.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by lh on 2017/8/1.
 */
@Component
public class SmsApi {
    @Autowired
    private SmsSender smsSender;

    /**
     * 发送登录验证码短信
     *
     * @param phone
     */
    public String loginVerifyCodeMsg(String phone) {
        Map<String, String> params = new HashMap<>();
        String verifyCode = RandomUtil.verifyCode(6);
        params.put("verifyCode", verifyCode);
        smsSender.send(phone, SmsTemplateName.LOGIN_VERIFY_NAME, SmsTemplateCode.LOGIN_VERIFY_CODE, ShortMessage.Type.LOGIN_VERIFY, params);
        return verifyCode;
    }
}
